package com.axjy.service.impl;

import com.axjy.mapper.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.http.client.support.HttpRequestWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

@Service("userSerivce")
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public Page<User> searchPage(Integer current, Integer size, User user) {
        Page<User> page=new Page<>(current,size);
        LambdaQueryWrapper<User> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(!StringUtils.isEmpty(user.getUsername()),User::getUsername,user.getUsername());
        wrapper.eq(user.getUserRole()!=null,User::getUserRole,user.getUserRole());
        userMapper.selectPage(page,wrapper);
        return page;
    }
}
